﻿using System.Data;
using Ledict.ConditionExtract.BLL;
using Ledict.ConditionExtract.BLL.LuceneSearchApi;
using Ledict.ConditionExtract.Common;

namespace Ledict.ConditionExtract.BLL.WorkProcess
{
    public class WorkThread_first : WorkThread
    {
        public WorkThread_first()
        {

        }
        
        /// <summary>
        /// 查询lucene中的目标文本（分页）
        /// </summary>
        /// <param name="condition">查询条件</param>
        /// <param name="page">第几页</param>
        /// <param name="perPage">每页几条</param>
        /// <returns>返回分页结果</returns>
        public DataTable GetDataSource(DataSourceCondition condition, int page, int perPage)
        {
            if (base.LuceneSearchType == "WCF")//查询索引方式：WCF服务/直接调用
            {
                using (var lucenenService = new LuceneSearchClient())
                {
                    return lucenenService.GetDataSource(condition, page, perPage);
                }
            }
            else //共享或本地直接访问索引文件夹
            {
                var luceneSearch = new LuceneSearch();
                return luceneSearch.GetDataSource(condition, page, perPage);
            }

        }

        /// <summary>
        /// 统计lucene中有目标文本的数量
        /// </summary>
        /// <param name="condition">条件</param>
        /// <returns></returns>
        public int GetDataSourceCount(DataSourceCondition condition)
        {
            if (base.LuceneSearchType == "WCF") //查询索引方式：WCF服务/直接调用
            {
                using (var lucenenService = new LuceneSearchClient())
                {
                    return lucenenService.GetDataSourceCount(condition);
                }
            }
            else  //共享或本地直接访问索引文件夹
            {
                var luceneSearch = new LuceneSearch();
                return luceneSearch.GetDataSourceCount(condition);
            }
        }






    }
}

